package com.one.shopping.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.one.shopping.AppContext;
import com.one.shopping.R;

import static com.one.shopping.util.Constant.SWITCH_GOODS_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_MEMBER_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_ORDERS_MANAGE_CODE;
import static com.one.shopping.util.Constant.SWITCH_USER_MANAGE_CODE;

/**
 * @author 柯尊诚
 * @version 1.0
 * @date 创建时间：2016/1/9 20:00
 */
public class AdminActivity extends FragmentActivity implements View.OnClickListener{

    private Button userBtn;
    private Button memberBtn;
    private Button goodsBtn;
    private Button ordersBtn;
    private Button loginOutBtn;
    private TextView titleValue;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_admin_list);
        initView();
        initListener();
    }

    /**
     * 设置标题
     */
    public void setTitle(String title) {
        if (titleValue != null) {
            titleValue.setText(title);
        }
    }

    protected void initView() {
        userBtn = findView(R.id.admin_user_manage_btn);
        memberBtn = findView(R.id.admin_member_manage_btn);
        goodsBtn = findView(R.id.admin_goods_manage_btn);
        ordersBtn = findView(R.id.admin_orders_manage_btn);
        loginOutBtn = findView(R.id.admin_loginout_btn);
        titleValue = findView(R.id.main_title_tv);

        setTitle("管理员界面");

    }

    protected void initListener() {
        userBtn.setOnClickListener(this);
        memberBtn.setOnClickListener(this);
        goodsBtn.setOnClickListener(this);
        ordersBtn.setOnClickListener(this);
        loginOutBtn.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.admin_user_manage_btn :
                SWITCH_MANAGE_CODE = SWITCH_USER_MANAGE_CODE;
                jump2ManageList();
                break;

            case R.id.admin_member_manage_btn :
                SWITCH_MANAGE_CODE = SWITCH_MEMBER_MANAGE_CODE;
                jump2ManageList();

                break;

            case R.id.admin_goods_manage_btn :
                SWITCH_MANAGE_CODE = SWITCH_GOODS_MANAGE_CODE;
                jump2ManageList();
                break;

            case R.id.admin_orders_manage_btn :
                SWITCH_MANAGE_CODE = SWITCH_ORDERS_MANAGE_CODE;
                jump2ManageList();
                break;

            case R.id.admin_loginout_btn :
                AppContext.getInstance().cleanLoginInfo();
                AppContext.showLoginActivity(AdminActivity.this);
                finish();
                break;

            case R.id.main_add_btn_iv :

                break;

        }
    }

    public void jump2ManageList() {
        Intent intent = new Intent(AdminActivity.this, AdminDetailFragmentActivity.class);
        startActivity(intent);
    }

    public <T extends View> T findView(int id) {
        return (T) super.findViewById(id);
    }




}
